<?php   

//	$nonce = $_REQUEST['_wpnonce'];
//	if (! wp_verify_nonce($nonce, $plugin_ref.'-updatesettings') ) die('Security check failed'); 
//	if (!current_user_can('manage_options')) die(__('You cannot edit the '.$plugin_name.' options.'));
//	check_admin_referer($plugin_ref.'-updatesettings');

	if ( $_POST['Reset'] == "true" ) {
		set_defaults();
		echo "<div class=\"updated\"><p>WordPress BT settings reset to default.</p></div>\n";
	}

	// Update Settings
    if( $_POST['wpbt_hidden'] == 'Y')  {  
        //Get new options values from form data sent  

        $dispmaxppage = $_POST['wpbt_dispmaxppage'];  
        $ptracker_url = $_POST['wpbt_ptracker_url'];  
        $btracker_url = $_POST['wpbt_btracker_url'];  

	// Update the DB with the new option values
        update_option('wpbt_dispmaxppage', mysql_real_escape_string($dispmaxppage));  
        update_option('wpbt_ptracker_url', mysql_real_escape_string($ptracker_url));  
        update_option('wpbt_btracker_url', mysql_real_escape_string($btracker_url));

	 ?>	
        <div class="updated"><p><strong><?php _e('Options saved.' ); ?></strong></p></div> 
        <?php  
    } else {  

        //Get Current DB Values for display  
        $dispmaxppage = get_option('wpbt_dispmaxppage');  
        $ptracker_url = get_option('wpbt_ptracker_url');  
        $btracker_url = get_option('wpbt_btracker_url');  

    }  

	function set_defaults() {
	        update_option('wpbt_dispmaxppage', 10);  
       	    update_option('wpbt_ptracker_url', "http://tracker.openbittorent.com/announce");  
	        update_option('wpbt_btracker_url', "http://tracker.publicbt.com/announce");
		}

	if (!is_array($options))
		set_defaults();
?> 

<div class="wrap">  
    <?php    echo "<h2>" . __( 'WordPress Bittorrent Lite Options', 'wpbt_trdom' ) . "</h2>"; ?> 
      
    <form name="wpbt_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">  
        <input type="hidden" name="wpbt_hidden" value="Y">  
	 
	 <?php if (function_exists('wp_nonce_field')) { wp_nonce_field($plugin_ref.'-updatesettings'); } ?>
        
	 <?php    echo "<h4>" . __( 'WordPress Bittorrent Torrent/Download Page Display Settings', 'wpbt_trdom' ) . "</h4>"; ?>  
        <p><?php _e("No of downloads per page: " ); ?><input type="number" name="wpbt_dispmaxppage" value="<?php echo $dispmaxppage; ?>" size="3"><?php _e(" ex: 10" ); ?></p>  
        <hr />  
        <?php    echo "<h4>" . __( 'WordPress Bittorrent Tracker Settings', 'wpbt_trdom' ) . "</h4>"; ?>  
        <p><?php _e("Announce URL: " ); ?><input type="text" name="wpbt_ptracker_url" value="<?php echo $ptracker_url; ?>" size="20"><?php _e(" ex: http://tracker.xyz.com/announce" ); ?></p>  
        <p><?php _e("Backup Announce URL: " ); ?><input type="text" name="wpbt_btracker_url" value="<?php echo $btracker_url; ?>" size="20"><?php _e(" ex: http://tracker.abc.com/announce" ); ?></p>  

	 <p class="submit"> <input type="submit" name="Submit" value="<?php _e('Update Options', 'wpbt_trdom' ) ?>" />  </p> 
 	</form>
	<form action="" method="post">
		<input type="hidden" name="Reset" value="true"/>
		<p class="submit"><input type="submit" value="<?php _e('Reset Default Settings', 'wpbt_trdrom') ?>" />
		</p>
	</form>
</div>